package org.altervista.cp.thinjdbc.wrappers;

import java.io.InputStream;
import java.io.Reader;
import java.sql.NClob;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;

public abstract class PreparedStatement4 extends PreparedStatement {

	public Connection4 getConnection() {
		return (Connection4) super.getConnection();
	}

	public ResultSet4 getResultSet() {
		return (ResultSet4) super.getResultSet();
	}

	public ResultSet4 executeQuery() {
		return (ResultSet4) super.executeQuery();
	}

	public ResultSet4 executeQuery(String sql) {
		return (ResultSet4) super.executeQuery(sql);
	}

	public ResultSet4 getGeneratedKeys() {
		return (ResultSet4) super.getGeneratedKeys();
	}

	public void setAsciiStream(int parameterIndex, InputStream x, long length) {
		new AsciiStreamParameter(parameterIndex, x, length).setParameter();
	}

	public void setAsciiStream(int parameterIndex, InputStream x) {
		new AsciiStreamParameter(parameterIndex, x).setParameter();
	}

	public void setBinaryStream(int parameterIndex, InputStream x, long length) {
		new BinaryStreamParameter(parameterIndex, x, length).setParameter();
	}

	public void setBinaryStream(int parameterIndex, InputStream x) {
		new BinaryStreamParameter(parameterIndex, x).setParameter();
	}

	public void setBlob(int parameterIndex, InputStream inputStream, long length) {
		new BinaryStreamParameter(parameterIndex, inputStream, length)
				.setParameter();
	}

	public void setBlob(int parameterIndex, InputStream inputStream) {
		new BinaryStreamParameter(parameterIndex, inputStream).setParameter();
	}

	public void setCharacterStream(int parameterIndex, Reader reader,
			long length) {
		new CharacterStreamParameter(parameterIndex, reader, length)
				.setParameter();
	}

	public void setCharacterStream(int parameterIndex, Reader reader) {
		new CharacterStreamParameter(parameterIndex, reader).setParameter();
	}

	public void setClob(int parameterIndex, Reader reader, long length) {
		new CharacterStreamParameter(parameterIndex, reader, length)
				.setParameter();
	}

	public void setClob(int parameterIndex, Reader reader) {
		new CharacterStreamParameter(parameterIndex, reader).setParameter();
	}

	public void setNCharacterStream(int parameterIndex, Reader reader,
			long length) {
		new NCharacterStreamParameter(parameterIndex, reader, length)
				.setParameter();
	}

	public void setNCharacterStream(int parameterIndex, Reader reader) {
		new NCharacterStreamParameter(parameterIndex, reader).setParameter();
	}

	public void setNClob(int parameterIndex, NClob value) {
		new NClob2Parameter(parameterIndex, value).setParameter();
	}

	public void setNClob(int parameterIndex, Reader reader, long length) {
		new NClobParameter(parameterIndex, reader, length).setParameter();
	}

	public void setNClob(int parameterIndex, Reader reader) {
		new NClobParameter(parameterIndex, reader).setParameter();
	}

	public void setNString(int parameterIndex, String value) {
		new NStringParameter(parameterIndex, value).setParameter();
	}

	public void setRowId(int parameterIndex, RowId x) {
		new RowIdParameter(parameterIndex, x).setParameter();
	}

	public void setSQLXML(int parameterIndex, SQLXML xmlObject) {
		new SQLXMLParameter(parameterIndex, xmlObject).setParameter();
	}

	public abstract boolean isClosed();

	public abstract boolean isPoolable();

	public abstract void setPoolable(boolean poolable);

	protected class AsciiStreamParameter extends Parameter<InputStream> {
		protected AsciiStreamParameter(int parameterIndex, InputStream value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			if (_args == null || _args.length == 0) {
				((java.sql.PreparedStatement) unwrap()).setAsciiStream(
						_parameterIndex, _value);
			} else {
				((java.sql.PreparedStatement) unwrap()).setAsciiStream(
						_parameterIndex, _value, (Long) _args[0]);
			}
		}
	}

	protected class BinaryStreamParameter extends Parameter<InputStream> {
		protected BinaryStreamParameter(int parameterIndex, InputStream value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			if (_args == null || _args.length == 0) {
				((java.sql.PreparedStatement) unwrap()).setBinaryStream(
						_parameterIndex, _value);
			} else {
				((java.sql.PreparedStatement) unwrap()).setBinaryStream(
						_parameterIndex, _value, (Long) _args[0]);
			}
		}
	}

	protected class BlobParameter extends Parameter<InputStream> {
		protected BlobParameter(int parameterIndex, InputStream value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			if (_args == null || _args.length == 0) {
				((java.sql.PreparedStatement) unwrap()).setBlob(
						_parameterIndex, _value);
			} else {
				((java.sql.PreparedStatement) unwrap()).setBlob(
						_parameterIndex, _value, (Long) _args[0]);
			}
		}
	}

	protected class CharacterStreamParameter extends Parameter<Reader> {
		protected CharacterStreamParameter(int parameterIndex, Reader value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			if (_args == null || _args.length == 0) {
				((java.sql.PreparedStatement) unwrap()).setCharacterStream(
						_parameterIndex, _value);
			} else {
				((java.sql.PreparedStatement) unwrap()).setCharacterStream(
						_parameterIndex, _value, (Long) _args[0]);
			}
		}
	}

	protected class ClobParameter extends Parameter<Reader> {
		protected ClobParameter(int parameterIndex, Reader value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			if (_args == null || _args.length == 0) {
				((java.sql.PreparedStatement) unwrap()).setClob(
						_parameterIndex, _value);
			} else {
				((java.sql.PreparedStatement) unwrap()).setClob(
						_parameterIndex, _value, (Long) _args[0]);
			}
		}
	}

	protected class NCharacterStreamParameter extends Parameter<Reader> {
		protected NCharacterStreamParameter(int parameterIndex, Reader value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			if (_args == null || _args.length == 0) {
				((java.sql.PreparedStatement) unwrap()).setNCharacterStream(
						_parameterIndex, _value);
			} else {
				((java.sql.PreparedStatement) unwrap()).setNCharacterStream(
						_parameterIndex, _value, (Long) _args[0]);
			}
		}
	}

	protected class NClobParameter extends Parameter<Reader> {
		protected NClobParameter(int parameterIndex, Reader value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			if (_args == null || _args.length == 0) {
				((java.sql.PreparedStatement) unwrap()).setNClob(
						_parameterIndex, _value);
			} else {
				((java.sql.PreparedStatement) unwrap()).setNClob(
						_parameterIndex, _value, (Long) _args[0]);
			}
		}
	}

	protected class NClob2Parameter extends Parameter<NClob> {
		protected NClob2Parameter(int parameterIndex, NClob value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			((java.sql.PreparedStatement) unwrap()).setNClob(_parameterIndex,
					_value);
		}
	}

	protected class NStringParameter extends Parameter<String> {
		protected NStringParameter(int parameterIndex, String value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			((java.sql.PreparedStatement) unwrap()).setNString(_parameterIndex,
					_value);
		}
	}

	protected class RowIdParameter extends Parameter<RowId> {
		protected RowIdParameter(int parameterIndex, RowId value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			((java.sql.PreparedStatement) unwrap()).setRowId(_parameterIndex,
					_value);
		}
	}

	protected class SQLXMLParameter extends Parameter<SQLXML> {
		protected SQLXMLParameter(int parameterIndex, SQLXML value,
				Object... args) {
			super(parameterIndex, value, args);
		}

		protected void set() throws SQLException {
			((java.sql.PreparedStatement) unwrap()).setSQLXML(_parameterIndex,
					_value);
		}
	}

}
